{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "参考：\n",
    "- [WSL搭建Java开发环境](https://blog.csdn.net/c13232906050/article/details/83025020?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task)\n",
    "- [Windows Subsystem for Linux入门：安装+配置图形界面+中文环境+工作环境（vscode](https://blog.csdn.net/w_weilan/article/details/82862913?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task)\n",
    "\n",
    "\n",
    "相对于虚拟机的优势\n",
    "===\n",
    "\n",
    "相比于VMware等虚拟机，WSL占用内存和CPU资源更少，在WSL上运行软件的消耗和直接在Windows上差不多。而且，Windows下可以直接访问WSL的环境。\n",
    "\n",
    "安装 WSL Ubuntu 18.04\n",
    "===================\n",
    "\n",
    "安装按着的官方文档来：\n",
    "\n",
    "- [WSL 1](https://docs.microsoft.com/zh-cn/windows/wsl/about)\n",
    "- [WSL 2](https://docs.microsoft.com/zh-cn/windows/wsl/wsl2-index)\n",
    "\n",
    "\n",
    "**注意**wsl2需要Insider Previe版本，个人在更新版本的时候因为杀毒软件的原因在重启的时候会绿屏报“PAGE_FAULT_IN_NONPAGED_AREA”，错误代码0xc1900101，引以为戒。\n",
    "\n",
    "\n",
    "linux发行版选择了Ubuntu 18.04LTS，MIcrosoft Store还有其他发行版可供选择。这里没有的发行版可以自行折腾（如Arch ）。\n",
    "\n",
    "可以在Microsoft Store中安装**Windows Terminal**，可以快速打开wsl的终端。\n",
    "\n",
    "# 修改apt源，加快下载速度（选）\n",
    "\n",
    "## 1. 查看 Linux 版本\n",
    "\n",
    "```sh\n",
    "$ lsb_release -a\n",
    " \n",
    "Distributor ID: Ubuntu\n",
    "Description:    Ubuntu 18.04.3 LTS\n",
    "Release:        18.04\n",
    "Codename:       bionic\n",
    "```\n",
    "\n",
    "注意：Codename 为**bionic**\n",
    "\n",
    "当前 Ubuntu 的版本为 Bionic Beaver（仿生海狸）\n",
    "\n",
    "## 备份数据源\n",
    "\n",
    "```sh\n",
    "$ sudo cp /etc/apt/sources.list /etc/apt/sources-backup.list\n",
    "```\n",
    "\n",
    "## 编辑sources.list\n",
    "\n",
    "```sh\n",
    "$ sudo vim /etc/apt/sources.list\n",
    "```\n",
    "\n",
    "## 更换 sources.list 内容\n",
    "\n",
    "**阿里源**\n",
    "\n",
    "以下配置可能略有不同，原则上是将所有deb和deb-src后面的地址都替换为一样的即可。\n",
    "\n",
    "```\n",
    "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse\n",
    "deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse\n",
    "deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse\n",
    "deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse\n",
    "deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n",
    "deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse\n",
    "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse\n",
    "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse\n",
    "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse\n",
    "deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n",
    "```\n",
    "\n",
    "**163 源**\n",
    "\n",
    "<http://mirrors.163.com/ubuntu/>\n",
    "\n",
    "**中科大源**\n",
    "\n",
    "<https://mirrors.ustc.edu.cn/ubuntu/>\n",
    "\n",
    "## 更新源\n",
    "\n",
    "\n",
    "```sh\n",
    "$ sudo apt-get update\n",
    "$ sudo apt-get upgrade\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* * *\n",
    "\n",
    "Install xfce desktop\n",
    "====================\n",
    "\n",
    "注：直接安装整个`xfce4`桌面来安装所需的图形界面组件（idea，eclipse 等需要图形界面，或者自己单独安装需要的组件）\n",
    "\n",
    "```sh\n",
    "apt install xfce4\n",
    "```\n",
    "\n",
    "* * *\n",
    "\n",
    "Specify the display server\n",
    "==========================\n",
    "\n",
    "在`~/.bashrc`添加\n",
    "\n",
    "```\n",
    "export DISPLAY=:0.0\n",
    "export LIBGL_ALWAYS_INDIRECT=1\n",
    "```\n",
    "\n",
    "* * *\n",
    "\n",
    "Install VcXsrv\n",
    "==============\n",
    "\n",
    "Install the lastest version of [VcXsrv](https://sourceforge.net/projects/vcxsrv/).\n",
    "\n",
    "* * *\n",
    "\n",
    "Open display server\n",
    "===================\n",
    "\n",
    "Open **XLaunch**, choose “One large window” or “One large window without titlebar” and set the “display number” to 0.  \n",
    "Other settings leave as default and finish the configuration.\n",
    "\n",
    "![pic](../assets/20181012115854683.png)\n",
    "\n",
    "* * *\n",
    "\n",
    "Run xfce desktop\n",
    "================\n",
    "\n",
    "运行`bash`\n",
    "\n",
    "```\n",
    "startxfce4\n",
    "```\n",
    "\n",
    "* * *\n",
    "\n",
    "Fix powerline fonts rendering（选）\n",
    "================================\n",
    "\n",
    "Install the lastest version of [Hack](https://github.com/source-foundry/Hack#linux) fonts.\n",
    "\n",
    "* * *\n",
    "\n",
    "Fix Unicode fonts rendering（选）\n",
    "==============================\n",
    "\n",
    "```sh\n",
    "sudo apt-get install fonts-noto\n",
    "sudo apt-get install fonts-noto-hinted\n",
    "sudo apt-get install fonts-noto-mono\n",
    "sudo apt-get install fonts-noto-unhinted\n",
    "```\n",
    "\n",
    "* * *\n",
    "\n",
    "Fix Chinese fonts rendering（选）\n",
    "==============================\n",
    "\n",
    "```sh\n",
    "sudo apt-get install fonts-noto-cjk\n",
    "```\n",
    "\n",
    "* * *\n",
    "\n",
    "Install Chinese input method（选）\n",
    "===============================\n",
    "\n",
    "1.Install fcitx\n",
    "---------------\n",
    "\n",
    "```sh\n",
    "sudo apt-get install fcitx\n",
    "sudo apt-get install fcitx-pinyin\n",
    "```\n",
    "\n",
    "2.Add the following command to your bashrc file\n",
    "-----------------------------------------------\n",
    "\n",
    "在`~/.bashrc`添加\n",
    "\n",
    "```sh\n",
    "export XMODIFIERS=@im=fcitx\n",
    "export GTK_IM_MODULE=fcitx\n",
    "export QT_IM_MODULE=fcitx\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* * *\n",
    "\n",
    "安装开发软件\n",
    "======\n",
    "\n",
    "Python\n",
    "---\n",
    "```sh\n",
    "sudo apt install python python3 python-pip python3-pip\n",
    "#更换国内pip源\n",
    "mkdir ~/pip\n",
    "vim pip.conf\n",
    "\n",
    "[global]\n",
    "timeout = 6000\n",
    "index-url = https://pypi.mirrors.ustc.edu.cn/simple\n",
    "trusted-host = pypi.mirrors.ustc.edu.cn\n",
    "```\n",
    "\n",
    "安装 Java\n",
    "-------\n",
    "\n",
    "简单起见，直接`apt install openjdk-8-jdk`  \n",
    "或用 [Oracle 的 jdk](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)\n",
    "\n",
    "安装 idea\n",
    "-------\n",
    "\n",
    "[下载解压](https://www.jetbrains.com/idea/download/#section=linux)\n",
    "\n",
    "方便启动，加入到 PATH\n",
    "\n",
    "```sh\n",
    "# idea\n",
    "export IDEA_HOME=/opt/idea\n",
    "export PATH=$IDEA_HOME/bin:$PATH\n",
    "```\n",
    "\n",
    "安装 dbeaver\n",
    "----------\n",
    "\n",
    "[下载解压](https://dbeaver.io/download/)\n",
    "\n",
    "方便启动，加入到 PATH\n",
    "\n",
    "```sh\n",
    "# dbeaver\n",
    "export DBEAVER_HOME=/opt/dbeaver/current\n",
    "export PATH=$DBEAVER_HOME:$PATH\n",
    "```\n",
    "\n",
    "安装 RedisDesktopManager\n",
    "----------------------\n",
    "\n",
    "**完整版（给个 star）：**[**RedisDesktopManager-Linux-WSL**](https://github.com/archongum/RedisDesktopManager-Linux-WSL)\n",
    "\n",
    "```\n",
    "# need to upgrade\n",
    "apt update && apt upgrade\n",
    "\n",
    "# change to latest tag\n",
    "git clone --recursive https://github.com/uglide/RedisDesktopManager.git -b 0.9.8\n",
    "\n",
    "cd RedisDesktopManager/\n",
    "cd src/\n",
    "./configure\n",
    "qmake\n",
    "make\n",
    "make install\n",
    "\n",
    "cd /opt/redis-desktop-manager/\n",
    "mv qt.conf qt.backup\n",
    "\n",
    "# optional, reduces rdm size 30MB+ to 2MB+\n",
    "strip rdm\n",
    "```\n",
    "\n",
    "方便启动，加入到 PATH\n",
    "\n",
    "```\n",
    "# RDM\n",
    "export RDM_HOME=/opt/redis-desktop-manager\n",
    "export PATH=$RDM_HOME:$PATH\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "其他\n",
    "==\n",
    "\n",
    "汇总需要添加到. bashrc\n",
    "---------------\n",
    "\n",
    "```sh\n",
    "export DISPLAY=:0.0\n",
    "export LIBGL_ALWAYS_INDIRECT=1\n",
    "\n",
    "#pinyin\n",
    "export XMODIFIERS=@im=fcitx\n",
    "export GTK_IM_MODULE=fcitx\n",
    "export QT_IM_MODULE=fcitx\n",
    "\n",
    "# dbeaver\n",
    "export DBEAVER_HOME=/opt/dbeaver/current\n",
    "export PATH=$DBEAVER_HOME:$PATH\n",
    "\n",
    "# idea\n",
    "export IDEA_HOME=/opt/idea/current\n",
    "export PATH=$IDEA_HOME/bin:$PATH\n",
    "\n",
    "# RDM\n",
    "export RDM_HOME=/opt/redis-desktop-manager\n",
    "export PATH=$RDM_HOME:$PATH\n",
    "```\n",
    "\n",
    "TheFuck\n",
    "---\n",
    "\n",
    "```sh\n",
    "pip install thefuck\n",
    "```\n",
    "\n",
    "Git 修改信息和记住密码\n",
    "-------------\n",
    "\n",
    "```sh\n",
    "git config --global user.name archon\n",
    "git config --global user.email qq349074225@live.com\n",
    "git config --global credential.helper store\n",
    "```\n",
    "\n",
    "安装字体\n",
    "----\n",
    "\n",
    "1.  复制字体到`/usr/share/fonts/${自己新建的目录}`\n",
    "2.  运行`fc-cache -f -v`\n",
    "3.  参考 [link1](https://github.com/source-foundry/Hack#linux), [link2](https://blog.csdn.net/bitcarmanlee/article/details/79729634)\n",
    "\n",
    "alias\n",
    "---\n",
    "\n",
    "```sh\n",
    "cp /mnt/e/.bashrc ~/\n",
    "或\n",
    "vim .bashrc\n",
    "```\n",
    "\n",
    "```sh\n",
    "alias p='cd ..'\n",
    "alias b='cd -'\n",
    "alias e='cd /mnt/e'\n",
    "alias city='cd /mnt/c/Users/City/Desktop'\n",
    "alias work='cd /mnt/e/Workspace'\n",
    "alias py='cd /mnt/e/Workspace/py'\n",
    "alias cpp='cd /mnt/e/Workspace/c++'\n",
    "alias c='clear'  # =左右不能有空格\n",
    "alias x='startxfce4'\n",
    "alias ip='ifconfig'\n",
    "alias py3='python3'\n",
    "alias tar='tar -zxvf'\n",
    "```\n",
    "\n",
    "参考文档\n",
    "====\n",
    "\n",
    "[RedisDesktopManager-Linux-WSL](https://github.com/archongum/RedisDesktopManager-Linux-WSL)  \n",
    "[wsl-tutorial](https://github.com/QMonkey/wsl-tutorial)  \n",
    "[redisdesktop linux](http://docs.redisdesktop.com/en/latest/install/#ubuntu-debian-fedora-centos-opensuse-archlinux-other-linux-di)  \n",
    "[redisdesktop build fail](https://github.com/uglide/RedisDesktopManager/issues/4118)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "232.807px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
